// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/tools/quic/quic_epoll_clock.h"

#include "net/tools/quic/test_tools/mock_epoll_server.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace net {
namespace test {

    TEST(QuicEpollClockTest, ApproximateNowInUsec)
    {
        MockEpollServer epoll_server;
        QuicEpollClock clock(&epoll_server);

        epoll_server.set_now_in_usec(1000000);
        EXPECT_EQ(1000000,
            clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds());
        EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds());
        EXPECT_EQ(1000000u, clock.WallNow().ToUNIXMicroseconds());

        epoll_server.AdvanceBy(5);
        EXPECT_EQ(1000005,
            clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds());
        EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds());
        EXPECT_EQ(1000005u, clock.WallNow().ToUNIXMicroseconds());

        epoll_server.AdvanceBy(10 * 1000000);
        EXPECT_EQ(11u, clock.WallNow().ToUNIXSeconds());
        EXPECT_EQ(11000005u, clock.WallNow().ToUNIXMicroseconds());
    }

    TEST(QuicEpollClockTest, NowInUsec)
    {
        MockEpollServer epoll_server;
        QuicEpollClock clock(&epoll_server);

        epoll_server.set_now_in_usec(1000000);
        EXPECT_EQ(1000000, clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds());

        epoll_server.AdvanceBy(5);
        EXPECT_EQ(1000005, clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds());
    }

} // namespace test
} // namespace net
